 using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

ля-kz-ля


namespace ParaprogrammingMatrix
{
    public enum MatrixSourceType
    {
        Random
    }

    class Matrix
    {
        private List<List<int>> _rows = new List<List<int>>();
        private readonly List<List<int>> _cols = new List<List<int>>();

        public List<List<int>> Rows
        {
            get { return _rows; }
            set
            {
                if (value == null) return;
                _rows = value;
                try
                {
                    for (var i = 0; i < _rows[0].Count; i++)
                    {
                        var t = new List<int>(_rows.Count);
                        t.AddRange(_rows.Select(t1 => t1[i]));
                        _cols.Add(t);
                    }
                }
                catch
                {
                    Console.WriteLine(@"What a fuck?");
                    MessageBox.Show(@"Error");
                }
            }
        }

        public List<List<int>> Coloumns
        {
            get { return _cols; }
        }

        public Matrix() { }

        /// <summary>
        /// Конструктор создаёт квадратную матрицу NxN из случ. чисел от 10 до 99
        /// </summary>
        /// <param name="n"></param>
        public Matrix(int n)
        {
            var r = new Random();
            var u = new List<List<int>>(n);
            for (var i = 0; i < n; i++)
            {
                var v = new List<int>(n);
                for (var j = 0; j < n; j++)
                    v.Add(r.Next(10, 99));
                u.Add(v);
            }
            Rows = u;
        }
    }

    class Multiplier
    {
        private readonly Thread _th;
        private readonly int _from, _to;
        private readonly Matrix _a, _b;
        private List<int> _oneRow;
        public List<List<int>> Result { get; private set; }
        public bool IsReady;

        public Multiplier(Matrix a, Matrix b, int startRow, int endRow)
        {
            _th = new Thread(ThreadHandler);
            Result = new List<List<int>>();
            _a = a;
            _b = b;
            _from = startRow;
            _to = endRow;
        }

        private void ThreadHandler()
        {
            try
            {
                for (var i = _from; i < _to; i++)
                {
                    _oneRow = new List<int>();
                    for (var j = 0; j < _b.Coloumns.Count; j++)
                    {
                        var t = 0;
                        for (var k = 0; k < _a.Coloumns.Count; k++)
                            t += _a.Rows[i][k] * _b.Coloumns[j][k];
                        _oneRow.Add(t);
                    }
                    Result.Add(_oneRow);
                }
            }
            catch
            {
                Console.WriteLine(@"What a fuck?");
                MessageBox.Show(@"Error");
            }
            IsReady = true;
        }

        public void LetsGo()
        {
            _th.Start();
        }
    }
}
